package com.example.test.student;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.example.test.R;
import com.example.test.utils.Http;
import com.example.test.utils.MyApplication;

import java.util.LinkedHashMap;
import java.util.Map;

public class UserInfo extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        testUrl();

    }

    public void testUrl() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                StringBuilder url = new StringBuilder();

                String res;
                if (MyApplication.getGlobalvariable().equals("student")) {
                    res = Http.sendGet("http://36428pn632.qicp.vip/student/index.php/user/user/read?id="+ MyApplication.getGlobalID());
                } else {
                    res = Http.sendGet("http://36428pn632.qicp.vip/student/index.php/teacher/teacher/read?id="+ MyApplication.getGlobalID());
                }
                //                            object = new JSONObject(res);
                final LinkedHashMap<String, Object> hashMaps = Http.stringToJsonObject(res);
                Log.d("HttpGET", (String) hashMaps.get("msg"));
                runOnUiThread(new Runnable() {
                    TextView user_name = findViewById(R.id.user_name);
                    TextView user_num = findViewById(R.id.user_num);
                    TextView user_phone = findViewById(R.id.user_phone);
                    TextView user_class = findViewById(R.id.user_class);

                    @Override
                    public void run() {
                        Map result = (Map)hashMaps.get("result");
                        user_name.setText((String)result.get("name"));
                        user_num.setText((String)result.get("username"));
                        user_phone.setText((String)result.get("phone"));
                        user_class.setText((String)result.get("class"));
                    }
                });
            }
        }).start();
    }
}
